<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>分单号领取</title>
    <% include("/common/common_css_js.html"){} %>
</head>
<body>
    <div style="padding-bottom: 5px;">
        <div id="createBillNativeCodeForm" class="uc-toolbaroverflow" _borderStyle="border-top:0;">
            <span>领单部门：</span>
            <input id="departmentId" name="departmentId" class="mini-hidden" value="${departmentId}"/>
            <input id="departmentName" name="departmentName" class="mini-textbox" value="${departmentName}" enabled="false"/>
            <span class="separator"></span>
            <span>领单人：</span>
            <input id="userId" name="userId" class="mini-hidden" value="${userId}"/>
            <input id="userName" name="userName" class="mini-textbox" value="${userName}" enabled="false"/>
            <span class="separator"></span>
            <span>领单日期：</span>
            <input id="receiveDate" class="mini-datepicker" value="${currentDate}"  format="yyyy-MM-dd"/>
            <span class="separator"></span>
            <span>单号范围：</span>
            <input id="startCode" name="startCode"  class="mini-textbox" required="true" requiredErrorText="起始分单号不能为空"/>--<input id="endCode" name="endCode"  class="mini-textbox" required="true" requiredErrorText="结束分单号不能为空"/>

            <span class="separator"></span>
            <% if(so.hasPermission("bNativeBillCode:generate")){%>
            <a class="mini-button" iconCls="icon-add" onclick="generateCode()">生成</a>
            <% } %>

            <span class="separator"></span>

            <% if(so.hasPermission("bNativeBillCode:save")){%>
            <a class="mini-button" iconCls="icon-save" onclick="saveCode()">保存</a>
            <% } %>

        </div>
    </div>

    <div class = "mini-fit">
        <div id="datagrid1" class="mini-datagrid"
             style="width: 100%; height: 100%;"
             url="${base}/pages/bill_code_manage/b_native/showCode?userId=${userId}" idField="id"
             showPager="false" pageSize="1000" sizeList="[1000,2000]"  multiSelect="true"
             allowResize="true"
             allowCellWrap="true">
            <div property="columns">
                <div type="checkcolumn" ></div>
                <div field="id" width="140" headerAlign="center" align="center" allowSort="true">分单号</div>
                <div field="useStatusId" width="140" headerAlign="center" align="center" allowSort="true" data-options='{cacheName:"sysDic"}' renderer="commonRender">使用状态</div>
                <div field="generateDepartmentId" width="140" headerAlign="center" align="center" allowSort="true" data-options='{cacheName:"department"}' renderer="commonRender">领单部门</div>
                <div field="generateDate" width="140" headerAlign="center" align="center" allowSort="true" dateFormat="yyyy-MM-dd" renderer="ondayRenderer">领单日期</div>
                <div field="generateUserId" width="140" headerAlign="center" align="center" data-options='{cacheName:"sysUser"}' renderer="commonRender">领单人</div>
                <div field="useDepartmentId" width="140" headerAlign="center" align="center" allowSort="true" data-options='{cacheName:"department"}' renderer="commonRender">使用部门</div>
                <div field="useUserId" width="140" headerAlign="center" align="center" allowSort="true" data-options='{cacheName:"sysUser"}' renderer="commonRender">使用人</div>
            </div>
        </div>
    </div>
    <script type="text/javascript">
        mini.parse();
        var departmentId = mini.get("departmentId");
        var userId = mini.get("userId");
        var startCode = mini.get("startCode");
        var endCode = mini.get("endCode");
        var receiveDate = mini.get("receiveDate");
        var datagrid1 = mini.get("datagrid1");

        var createBillNativeCodeForm = new mini.Form("#createBillNativeCodeForm");

        $(function () {

        });


        /**
         * 生成单号
         */
        function generateCode() {

            if (createBillNativeCodeForm.isValid() == false){
                public_showErrorTips("请将信息填写完整再进行下一步！");
                return;
            }
            var startCodeValue=startCode.getValue();
            var endCodeValue=endCode.getValue();

            if(startCodeValue>=endCodeValue){
                public_showErrorTips("起始分单号不小于结束分单号，不能生成!");
                return;
            }
            var data = createBillNativeCodeForm.getData(true);
            data.receiveDate = receiveDate.getFormValue().trim();
            var ret = public_getServerData("${base}/pages/bill_code_manage/b_native/generateCode",data);
            if(ret.ok) {
                public_showTip(ret);
                // 重新刷新数据
                datagrid1.load();
            }

        }

        /**
         * 保存入库
         */
        function saveCode() {

            var rows=datagrid1.getSelecteds();

            if (rows.length > 0){
                var ret = public_getServerData("${base}/pages/bill_code_manage/b_native/saveCode",rows);
                public_showTip(ret);
            }
            else{
                public_showErrorTips("请选择要保存的单号！");
            }
        }

    </script>
</body>
</html>